home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
tifreadr.sit
/
Tiff Window DEMO
/
change color.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-30
|
8KB
|
187 lines
#include "my color.h"
/*
The routines in this module will change the chosen part of the window
or control to whatever color the user wants .
*/
change_color(window_region, aWindow) /* this will change a window's color */
CWindowPtr aWindow;
short window_region;
{
Point center = {0, 0}; /* This will tell "GetColor" to center the dialog window */
RGBColor selected_color;
AuxWinHndl some_new_colors = 0;/* This is really dumb, but LSC calls AuxWinHandle, AuxWinHndl??? */
Boolean aux_test;
GetPort(&savedPort); /* Save the Graf Port */
/* WARNING: Inside Mac Vol 5 document bug! */
/* Inside Mac Vol 5 on page 207 defines GetAuxWin as returning a CTabHandle,
This is wrong, it really returns an AuxWinHandle!!!! this drove me crazy for
an hour before I realized that it didn't make since for GetAuxWin to return
a CTabHandle. It made more sense for it to return an AuxWinHandle. (Note
the AuxWin in both words) Some quick experimenting with the Think C
source Code Debugger proved this to be correct!
P.S. If you believe Inside Mac and treat GetAuxWin as returning a CTabHandle
you will notice that your program will do strange things and then
really bomb!
*/
/* I want to call GetAuxWin to get the window's ColorTable that I created when the window
was first defined, then I can change the colors the way the user wants */
aux_test = GetAuxWin(aWindow, &some_new_colors); /* get this window's current color definitions */
if(!aux_test) /* if there are no Auxillary window records then lets scram! */
return;
HLock((**some_new_colors).awCTable); /* Lock it just in case SetWinColor or GetColor de-references the Handle */
switch(window_region) /* depending on which part of the window they want to change the color */
{
case CONTENT:
if(!GetColor(center, "\pContent Region",
&(**(**some_new_colors).awCTable).ctTable[0].rgb, &selected_color))
{ SysBeep(10); return; }
(**(**some_new_colors).awCTable).ctTable[0].value = wContentColor;
(**(**some_new_colors).awCTable).ctTable[0].rgb.red = selected_color.red;
(**(**some_new_colors).awCTable).ctTable[0].rgb.green = selected_color.green;
(**(**some_new_colors).awCTable).ctTable[0].rgb.blue = selected_color.blue;
break;
case FRAME:
if(!GetColor(center, "\pWindow Frame",
&(**(**some_new_colors).awCTable).ctTable[1].rgb, &selected_color))
{ SysBeep(10); return; }
(**(**some_new_colors).awCTable).ctTable[1].value = wFrameColor;
(**(**some_new_colors).awCTable).ctTable[1].rgb.red = selected_color.red;
(**(**some_new_colors).awCTable).ctTable[1].rgb.green = selected_color.green;
(**(**some_new_colors).awCTable).ctTable[1].rgb.blue = selected_color.blue;
break;
case TEXT:
if(!GetColor(center, "\pWindow Text",
&(**(**some_new_colors).awCTable).ctTable[2].rgb, &selected_color))
{ SysBeep(10); return; }
(**(**some_new_colors).awCTable).ctTable[2].value = wTextColor;
(**(**some_new_colors).awCTable).ctTable[2].rgb.red = selected_color.red;
(**(**some_new_colors).awCTable).ctTable[2].rgb.green = selected_color.green;
(**(**some_new_colors).awCTable).ctTable[2].rgb.blue = selected_color.blue;
break;
case HILITE:
if(!GetColor(center, "\pHilite Color",
&(**(**some_new_colors).awCTable).ctTable[3].rgb, &selected_color))
{ SysBeep(10); return; }
(**(**some_new_colors).awCTable).ctTable[3].value = wHiliteColor;
(**(**some_new_colors).awCTable).ctTable[3].rgb.red = selected_color.red;
(**(**some_new_colors).awCTable).ctTable[3].rgb.green = selected_color.green;
(**(**some_new_colors).awCTable).ctTable[3].rgb.blue = selected_color.blue;
break;
case TITLE:
if(!GetColor(center, "\pTitle Bar",
&(**(**some_new_colors).awCTable).ctTable[4].rgb, &selected_color))
{ SysBeep(10); return; }
(**(**some_new_colors).awCTable).ctTable[4].value = wTitleBarColor;
(**(**some_new_colors).awCTable).ctTable[4].rgb.red = selected_color.red;
(**(**some_new_colors).awCTable).ctTable[4].rgb.green = selected_color.green;
(**(**some_new_colors).awCTable).ctTable[4].rgb.blue = selected_color.blue;
break;
}
SetWinColor(aWindow, (**some_new_colors).awCTable);
HUnlock((**some_new_colors).awCTable); /* Now that SetWinColor is done, I'll unlock the handle */
SetPort(savedPort); /* restore the Graf Port */
}
/*
Change_control_color will take the indicated control componet from the
selected window and the prompt the user for the desired color
NOTE: If there exists more than one control with the same componet, then
change_control_coor will change the componet for all the controls.
the user will be prompted for the color for each scroll bar
*/
change_control_color(control_region, aWindow) /* this will change a scroll bar's color */
CWindowPtr aWindow;
short control_region;
{
Point center = {0, 0}; /* This will tell "GetColor" to center the dialog window */
RGBColor selected_color;
AuxCtlHndl some_new_colors = 0;
Boolean aux_test;
CWindowPeek peek;
ControlHandle control;
CGrafPtr savedPort;
GetPort(&savedPort); /* Save the Graf Port */
/* I want to call GetAuxCtl to get the window's ColorTable that I created when the window
was first defined, then I can change the colors the way the user wants */
peek = (CWindowPeek)aWindow;
control = peek->controlList; /* get the first control */
while(control)
{
aux_test = GetAuxCtl(control, &some_new_colors); /* get this window's current color definitions */
if(!aux_test) /* if there are no Auxillary Control records then lets skip this control! */
break;
HLock((**some_new_colors).acCTable); /* Lock it just in case SetCtlColor or GetColor de-references the Handle */
switch(control_region) /* depending on which part of the window they want to change the color */
{
case cFRAME:
if(!GetColor(center, "\pControl Frame",
&(**(**some_new_colors).acCTable).ctTable[0].rgb, &selected_color))
{ SysBeep(10); break; }
(**(**some_new_colors).acCTable).ctTable[0].value = cFrameColor;
(**(**some_new_colors).acCTable).ctTable[0].rgb.red = selected_color.red;
(**(**some_new_colors).acCTable).ctTable[0].rgb.green = selected_color.green;
(**(**some_new_colors).acCTable).ctTable[0].rgb.blue = selected_color.blue;
break;
case cBODY:
if(!GetColor(center, "\pControl Body",
&(**(**some_new_colors).acCTable).ctTable[1].rgb, &selected_color))
{ SysBeep(10); break; }
(**(**some_new_colors).acCTable).ctTable[1].value = cBodyColor;
(**(**some_new_colors).acCTable).ctTable[1].rgb.red = selected_color.red;
(**(**some_new_colors).acCTable).ctTable[1].rgb.green = selected_color.green;
(**(**some_new_colors).acCTable).ctTable[1].rgb.blue = selected_color.blue;
break;
case cTEXT:
if(!GetColor(center, "\pControl Text",
&(**(**some_new_colors).acCTable).ctTable[2].rgb, &selected_color))
{ SysBeep(10); break; }
(**(**some_new_colors).acCTable).ctTable[2].value = cTextColor; /* I'm not totally certain what this does for a scroll bar */
(**(**some_new_colors).acCTable).ctTable[2].rgb.red = selected_color.red;
(**(**some_new_colors).acCTable).ctTable[2].rgb.green = selected_color.green;
(**(**some_new_colors).acCTable).ctTable[2].rgb.blue = selected_color.blue;
break;
case cTHUMB:
if(!GetColor(center, "\pScroll Thumb",
&(**(**some_new_colors).acCTable).ctTable[3].rgb, &selected_color))
{ SysBeep(10); break; }
(**(**some_new_colors).acCTable).ctTable[3].value = cThumbColor;
(**(**some_new_colors).acCTable).ctTable[3].rgb.red = selected_color.red;
(**(**some_new_colors).acCTable).ctTable[3].rgb.green = selected_color.green;
(**(**some_new_colors).acCTable).ctTable[3].rgb.blue = selected_color.blue;
break;
}
SetCtlColor(control, (**some_new_colors).acCTable);
HUnlock((**some_new_colors).acCTable); /* Now that SetCtlColor is done, I'll unlock the handle */
control = (*control)->nextControl;
}
SetPort(savedPort); /* restore the Graf Port */
}